package com.wc.AlgoOJ_train.train5_数据结构.c7_单调栈与单调队列.最大矩形面积;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/25 23:31
 * @description http://43.138.190.70:8888/p/DS0602
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010;
    static int[] stk = new int[N];
    static int[] a = new int[N];
    static int[] l = new int[N];
    static int[] r = new int[N];
    static int top, n;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
        a[0] = a[n + 1] = -1;
        top = 0;
        stk[++top] = 0;
        for (int i = 1; i <= n; i++) {
            while (top >= 1 && a[i] <= a[stk[top]]) top--;
            l[i] = stk[top];
            stk[++top] = i;
        }
        top = 0;
        stk[++top] = n + 1;
        for (int i = n; i >= 1; i--) {
            while (top >= 1 && a[i] <= a[stk[top]]) top--;
            r[i] = stk[top];
            stk[++top] = i;
        }
        long res = 0;
        for (int i = 1; i <= n; i++) {
            res = Math.max(res, (long) a[i] * (r[i] - l[i] - 1));
        }
        out.println(res);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}